<?php
// module for generating html for VRML representation

function return_html($viewpoints){
    global $_GET, $session_id, $path, $style;
    $relation_check = Array();
    $relation_check[0] = '';$relation_check[1] = '';$relation_check[2] = '';$relation_check[3] = '';$relation_check[4] = '';$relation_check[5] = '';
    $taxonomy = 0; $acon = 0; $compability = 0; $hierarchy = 0; $inheritedattr = 0;
    if ((isset($_GET["taxonomy"]))&&($_GET["taxonomy"]==1)){
        $relation_check[1] = 'checked';
        $taxonomy = 1;
    };
    if ((isset($_GET["acon"]))&&($_GET["acon"]==1)){
        $relation_check[2] = 'checked';
        $acon = 1;
    };
    if ((isset($_GET["compability"]))&&($_GET["compability"]==1)){
        $relation_check[3] = 'checked';
        $compability = 1;
    };
    if ((isset($_GET["hierarchy"]))&&($_GET["hierarchy"]==1)){
        $relation_check[4] = 'checked';
        $hierarchy = 1;
    };
    if ((isset($_GET["inheritedattr"]))&&($_GET["inheritedattr"]==1)){
        $relation_check[5] = 'checked';
        $inheritedattr = 1;
    };

    if ((!isset($_GET["taxonomy"]))&&(!isset($_GET["acon"]))&&(!isset($_GET["compability"]))&&(!isset($_GET["hierarchy"]))){
        $relation_check[1] = 'checked';
        $taxonomy = 1;
    };

    if (isset($_GET["cid"]))
      $cid = $_GET["cid"];
    else
      $cid = -1;

    $ret_data = "<html><META http-equiv=Content-Type content='text/html; charset=utf-8'><link rel=\"stylesheet\" type=\"text/css\" href=\"".
                $path[$style]["css"]."/style.css\"><body>\n".//<form name=\"main\" method=\"GET\">
                "   <script>\n".
                "       var count_view_p = ".count($viewpoints).";\n".
                "       var viewpoints_name = [";
                for ($i = 0; $i < count($viewpoints)-1; $i++){
                    $ret_data .= "'".$viewpoints[$i]->name."',";
                };
    if (count($viewpoints) > 0)
        $ret_data .= "'".$viewpoints[count($viewpoints)-1]->name."'];\n";
    else
        $ret_data .= "];\n";

        $ret_data .= "       var viewpoints_id = [";
                for ($i = 0; $i < count($viewpoints)-1; $i++){
                    $ret_data .= "'".$viewpoints[$i]->id."',";
                };
    if (count($viewpoints) > 0)
        $ret_data .= "'".$viewpoints[count($viewpoints)-1]->id."'];\n";
    else
        $ret_data .= "];\n";

    $ret_data .="       function SetViewPoint(ID){\n".
                "           var b = false;\n".
                "           var class_id = '';\n".
                "           var re = '';\n".
                "           for (i = 0; i < count_view_p; i++){\n".
                "               re = /ab+c/;\n".
                "               if (ID == viewpoints_name[i]){\n".
                "                   class_id = 'view'+viewpoints_id[i];\n".
                "                   document.getElementById('VRMLID').Engine.Viewpoints(class_id).Fields('set_bind') = true;\n".
                "                   b = true;\n".
                "               }\n".
                "           }\n".
                "           if (b == false)\n".
                "               MessageText.innerText = '".getMessage("This class can not be found")."';\n".
                "           else\n".
                "               MessageText.innerText = '';\n".
                "       }\n".

                "       function OnButtonClick(){\n".
                "           alert('yes')".
                "           var s = '';\n".
                "           if (document.getElementById('taxonomy').checked == true)\n".
                "               s += '&taxonomy=1';\n".
                "           if (document.getElementById('acon').checked == true)\n".
                "               s += '&acon=1';\n".
                "           if (document.getElementById('compability').checked == true)\n".
                "               s += '&compability=1';\n".
                "           if (document.getElementById('hierarchy').checked == true)\n".
                "               s += '&hierarchy=1';\n".
                "           if (document.getElementById('inheritedattr').checked == true)\n".
                "               s += '&inheritedattr=1';\n".

                "           top.document.location.href = 'index.php?trg=ontoedit&act=vrml&sid=".$session_id."&uid=".$_GET["uid"]."'+s;\n".
                "       }\n".

                "   </script>\n".
                "   <div>\n".
                "       ".getMessage("Search Ontology:")." <input id=\"search\" type=\"text\">\n".
                "       &nbsp; <input type=\"button\" value=\"".getMessage("Search")."\" ".
                                    "onclick=\"javascript:SetViewPoint(document.getElementById('search').value);\">\n".
                "              <input type=\"checkbox\" id=\"taxonomy\" ".$relation_check[1].">".getMessage("Taxonomy")."\n".
                "              <input type=\"checkbox\" id=\"acon\" ".$relation_check[2].">".getMessage("Associative Constraints")."\n".
                "              <input type=\"checkbox\" id=\"compability\" ".$relation_check[3].">".getMessage("Compatibility")."\n".
                "              <input type=\"checkbox\" id=\"hierarchy\" ".$relation_check[4].">".getMessage("Hierarchy")."\n".
                "              <input type=\"checkbox\" id=\"inheritedattr\" ".$relation_check[5].">".getMessage("Inherited atributes")."\n".
                "              <INPUT id=\"show\" TYPE=\"button\" value=\"".getMessage("Show")."\" onclick=\"javascript:OnButtonClick();\">\n".
                "       <span id='MessageText'></span>\n".
                "   </div>\n".//</form>
                "   <div>\n".
                "       <embed id=\"VRMLID\" SRC=\"index.php?trg=ontoedit&act=vrml&world=1&sid=".
                                                $session_id."&uid=".$_GET["uid"].
                                                "&taxonomy=".$taxonomy."&acon=".$acon."&compability=".$compability."&hierarchy=".$hierarchy."&inheritedattr=".$inheritedattr."&cid=".$cid.
                                                "\" TYPE=\"x-world/x-vrml\" ".
                                                "WIDTH=\"100%\" HEIGHT=\"95.5%\">\n".
                "   </div>\n".
                "</body></html>";
    return $ret_data;
};
?>